package cn.ekuma.epos.datalogic.define.dao.sale.kitchen;

import java.util.HashMap;

import com.openbravo.bean.Product;
import com.openbravo.bean.sales.KitchenLine;
import com.openbravo.bean.sales.Ticket;
import com.openbravo.data.basic.BasicException;
import com.openbravo.data.loader.DataRead;
import com.openbravo.data.loader.DataWrite;
import com.openbravo.data.loader.Datas;
import com.openbravo.data.loader.I_Session;
import com.openbravo.data.loader.ImageUtils;
import com.openbravo.data.loader.TableDefinition;
import com.openbravo.data.model.Field;
import com.openbravo.format.Formats;

import cn.ekuma.data.dao.ModifiedLogDAO;
import cn.ekuma.epos.db.table.pos.kitchen.I_KitchenLine;
import cn.ekuma.util.JsonUtil;

public class KitchenLineDAO extends ModifiedLogDAO<KitchenLine>{

	public KitchenLineDAO(I_Session s) {
		super(s);
	}

	@Override
	public TableDefinition getTable() {
		return new TableDefinition(s,
                "KITCHEN_LINE",
                new Field[]{
				     new Field(I_KitchenLine.ID,Datas.STRING,Formats.STRING),
                     new Field(I_KitchenLine.TICKET,Datas.STRING,Formats.STRING,Ticket.class),
                     new Field(I_KitchenLine.LINE,Datas.INT,Formats.INT),
                     new Field(I_KitchenLine.PRODUCT,Datas.STRING,Formats.STRING,Product.class),
                     new Field(I_KitchenLine.ATTRIBUTESETINSTANCE_ID,Datas.STRING,Formats.STRING),
                     new Field(I_KitchenLine.UNITS,Datas.DOUBLE,Formats.DOUBLE),
                     new Field(I_KitchenLine.ATTRIBUTES,Datas.STRING,Formats.STRING),
                     new Field(I_KitchenLine.CURDATE,Datas.TIMESTAMP,Formats.TIMESTAMP),
                     new Field(I_KitchenLine.HOSTNAME,Datas.STRING,Formats.STRING),
                     new Field(I_KitchenLine.ORDERNUM,Datas.INT,Formats.INT),
                     new Field(I_KitchenLine.TICKETSTATE,Datas.INT,Formats.INT),
                     new Field(I_KitchenLine.LINESTATE,Datas.INT,Formats.INT),
                     new Field(I_KitchenLine.PLACE,Datas.STRING,Formats.STRING),
                     new Field(I_KitchenLine.URGENT,Datas.BOOLEAN,Formats.BOOLEAN),
                     new Field(I_KitchenLine.LASTMODIFIED,Datas.TIMESTAMP,Formats.TIMESTAMP), 
                     new Field(I_KitchenLine.USERID,Datas.STRING,Formats.STRING)
                    },
                new int[]{0});
	}

	@Override
	public KitchenLine readValues(DataRead dr,KitchenLine obj) throws BasicException {
		if(obj==null)
			obj=new KitchenLine();
		obj.setId(dr.getString(1));
		obj.setTicketId(dr.getString(2));
		obj.setTicketLineId(dr.getInt(3));
		obj.setProductid(dr.getString(4));
		obj.setAttsetinstid(dr.getString(5));
		
		obj.setMultiply(dr.getDouble(6));
		obj.setAttributes(JsonUtil.getHashMap(dr.getString(7)));
		obj.setCreatDate(dr.getTimestamp(8));
		obj.setHostName(dr.getString(9));
		obj.setOrder(dr.getInt(10));
		
		obj.setTicketState(dr.getInt(11));
		obj.setLineState(dr.getInt(12));
		obj.setTableName(dr.getString(13));
		obj.setUrgent(dr.getBoolean(14));
		obj.setLastModified(dr.getTimestamp(15));
		
		obj.setUserId(dr.getString(16));
		return obj;
	}

	@Override
	public void writeInsertValues(DataWrite dp, KitchenLine obj)
			throws BasicException {
		dp.setString(1,obj.getId());
		dp.setString(1,obj.getTicketId());
		dp.setInt(3,obj.getTicketLineId());
		dp.setString(4,obj.getProductid());
		dp.setString(5,obj.getAttsetinstid());
		
		dp.setDouble(6,obj.getMultiply());
		dp.setString(7,JsonUtil.toString(obj.getAttributes()));
		dp.setTimestamp(8,obj.getCreatDate());
		dp.setString(9,obj.getHostName());
		dp.setInt(10,obj.getOrder());
		
		dp.setInt(11,obj.getTicketState());
		dp.setInt(12,obj.getLineState());
		dp.setString(13,obj.getTableName());
		dp.setBoolean(14,obj.isUrgent());
		dp.setTimestamp(15,obj.getLastModified());
		
		dp.setString(16,obj.getUserId());
	}

	@Override
	public Class getSuportClass() {
		return KitchenLine.class;
	}

}
